import type { CloudFilterBarScheme } from '@/components/filter-bar/types'
import type { FilterItem } from '@/components/strong-search'

export default function useTableColumn() {
  const filterSchemes = computed<CloudFilterBarScheme>(() => {
    const strongSearchOptions: FilterItem[] = [
      {
        label: 'URL',
        field: 'url',
        maxLength: 30
      },
      {
        label: '站点',
        field: 'name'
      },
      {
        label: '规则 ID',
        field: 'waf_id',
        maxLength: 19,
        messageModel: 'message',
        message: '规则 ID 格式不正确',
        validate: validateRuleID
      },
      {
        label: '规则名称',
        field: 'waf_name'
      },
      {
        label: '规则类型',
        field: 'module',
        popover: 'select',
        popoverOption: {
          select: [
            { label: '所有类型', value: 0 },
            { label: '自定义规则', value: 1 },
            { label: '速率限制', value: 2 },
            { label: '白名单', value: 3 }
          ]
        }
      },
      {
        label: '请求 IP',
        field: 'ip'
      },
      {
        label: '请求地区',
        field: 'rep_region'
      },
      {
        label: '请求方法',
        field: 'method',
        popover: 'select',
        popoverOption: {
          select: [
            { label: 'GET', value: 'get' },
            { label: 'POST', value: 'post' },
            { label: 'DELETE', value: 'delete' },
            { label: 'PUT', value: 'put' },
            { label: 'OPTIONS', value: 'options' },
            { label: 'CONNECT', value: 'connect' },
            { label: 'HEAD', value: 'head' },
            { label: 'TRACE', value: 'trace' },
            { label: 'PATCHS', value: 'patchs' }
          ]
        }
      }
    ]
    return {
      widgets: [
        {
          widget: 'select',
          field: 'action',
          allText: '全部执行策略',
          options: [
            { label: '阻止', value: 1 },
            { label: '跳过', value: 2 },
            { label: '观察', value: 3 },
            { label: 'JS 质询', value: 4 },
            { label: '交互式质询', value: 5 }
          ]
        },
        {
          widget: 'strong-search',
          placeholder: '默认按照 URL 搜索',
          options: strongSearchOptions
        }
      ]
    }
  })
  const columnsList = ref([
    {
      title: '命中时间',
      dataIndex: 'time',
      format: 'date-time',
      width: 180,
      sortable: sortableSettings
    },
    {
      title: '请求 IP (地区)',
      dataIndex: 'rep_region',
      slotName: 'rep_region',
      width: 190
      //format: 'copy'
    },
    {
      title: 'URL',
      dataIndex: 'url',
      slotName: 'url',
      width: 200
      //format: 'copy'
    },
    {
      title: '站点',
      dataIndex: 'name',
      slotName: 'name',
      width: 200
    },
    {
      title: '站点区域',
      dataIndex: 'region',
      slotName: 'region',
      width: 200
    },
    {
      title: '规则 ID',
      dataIndex: 'waf_id',
      slotName: 'waf_id',
      width: 200
      //format: 'copy'
    },
    {
      title: '规则名称',
      dataIndex: 'waf_name',
      slotName: 'waf_name',
      width: 200
    },
    {
      title: '规则类型',
      dataIndex: 'module',
      slotName: 'module',
      width: 200
    },
    {
      title: '执行策略',
      dataIndex: 'action',
      slotName: 'action',
      width: 100
    },
    {
      title: '请求方法',
      dataIndex: 'method',
      slotName: 'method',
      width: 100
    },
    {
      title: 'HTTP 版本',
      dataIndex: 'http_version',
      slotName: 'http_version',
      width: 100
    },
    {
      title: '浏览器',
      dataIndex: 'browser',
      slotName: 'browser',
      width: 100
    },
    {
      title: '操作',
      width: 80,
      fixed: 'right',
      dataIndex: 'actions',
      slotName: 'actions'
    }
  ])
  return {
    columnsList,
    filterSchemes
  }
}
